package com.example.number1.ui.theme;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.number1.R;


/**
 * 1、带数据跳转，和数据返回显示到页面
 * 2、四种启动模式前三种带数据跳转显示到页面
 * 3、写两app,其中一个app去启动另外一个app
 * 4、简单计算器，实现加减乘除功能
 */
public class DatatransmissionActivity extends AppCompatActivity implements View.OnClickListener {

    private Button number1;
    private Intent intent;
    private TextView viewById;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent)
    { // 接收返回数据
        super.onActivityResult(requestCode, resultCode, intent);
        // 意图非空，且请求代码为之前传的0，结果代码也为成功
        if (intent!=null && requestCode==0 && resultCode== Activity.RESULT_OK) {
            Bundle bundle = intent.getExtras(); // 从返回的意图中获取快递包裹
        // 从包裹中取出名叫response_time的字符串
            String str2 = bundle.getString("str2");



            viewById.setText(str2); // 把返回消息的详情显示在文本视图上
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_datatransmission);

        number1 = findViewById(R.id.number1);

        viewById = findViewById(R.id.textnumber1);

        number1.setOnClickListener(this);




    }

    @Override
    public void onClick(View v) {

        Intent intent = new Intent(getApplicationContext(), DatatransmissionActivity2.class);

        intent.putExtra("str1", "我来了页面2");
        startActivityForResult(intent, 0);




    }

}